package com.example.swagger.service;

import com.example.swagger.entity.BookEntity;
import com.example.swagger.mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@Component
public class BookService {
    @Autowired
    private BookMapper bookMapper;

    public void insertBook(BookEntity u){
        bookMapper.insertBookRecord(u.getId(),u.getName(),u.isOnSale(),u.getPrice(),u.getPublish_date(),u.getAuthor_name());
    }

    public List<BookEntity> getBooksList(){
        return bookMapper.getBooks();
    }

    public BookEntity findBookById(Integer id){
        return bookMapper.findBookById(id);
    }

    public BookEntity updateBookById(BookEntity book) {
        return bookMapper.updateBook(book.getId(),book.getName(),book.isOnSale(),book.getPrice(),book.getPublish_date(),book.getAuthor_name());
    }

}
